package com._51cto.healthy.service;

import com._51cto.healthy.base.BaseMapper;
import com._51cto.healthy.content.P;
import com._51cto.healthy.mapper.MenuMapper;
import com._51cto.healthy.pojo.Menu;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class MenuServiceImpl implements MenuService {


    @Autowired
    private MenuMapper menuMapper;

    @Override
    public BaseMapper<Menu> getDao() {
        return menuMapper;
    }

    @Override
    public P<Menu> queryMenuAll(String query, Integer pageNum, Integer pageSize) {
        //开启分页
        PageHelper.startPage(pageNum,pageSize);
        List<Menu> menus = menuMapper.queryMenuAll(query);
        PageInfo<Menu> pageInfo = new PageInfo<>(menus);
        return new P().setPageNum(pageInfo.getPageNum())
                .setPageSize(pageInfo.getPageSize())
                .setPages(pageInfo.getPages())
                .setTotal(pageInfo.getTotal())
                .setRows(pageInfo.getList());
    }
}
